import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { LayuiVueResolver } from 'unplugin-vue-components/resolvers'
import { resolve } from "path";

const excludeComponents = ['LightIcon','DarkIcon']

export default defineConfig({
  resolve: {
    alias: [
      {
        find: '@',
        replacement: resolve(__dirname, './src')
      }
    ]
  },
  plugins: [
    AutoImport({
      resolvers: [
        LayuiVueResolver(),
      ],
    }),
    Components({
      resolvers: [
        LayuiVueResolver({
          resolveIcons: true,
          exclude: excludeComponents
        }),
      ],
    }),
    vue(),
  ],
  server: {
    cors: true,
    open: true,
    host: '0.0.0.0',
    port: 8991,
    proxy: {
      '/v1/api': {
          target: 'http://0.0.0.0:89',   //代理接口
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/api/, 'api')
      },      '/v2/api': {
          target: 'http://0.0.0.0:89',   //代理接口
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/api/, 'api')
      },
      '/websocket.ws/': {
        target: 'http://0.0.0.0:89',   //代理接口
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/websocket.ws/, 'websocket.ws')
    },
    //   '/asxsyd92upload': {
    //     target: 'http://asxsyd92.com',   //代理接口
    //     changeOrigin: true,
    //     rewrite: (path) => path.replace(/^\/api/, 'api')
    // }
    }
}
, build: {  
  // 指定使用terser进行压缩  
  minify: 'terser',  
  // 自定义terser选项  
  terserOptions: {  
    compress: {  
      drop_console: true, // 删除所有console语句  
      drop_debugger: true, // 删除所有debugger语句  
      // 可以添加更多terser选项...  
    },  
    // 其他terser选项...  
  },  
  // 其他构建选项...  
},  
});